Skip to content

Conversation

@kiwina
Copy link
Contributor

@kiwina kiwina commented Jun 2, 2025

PR for Clipboard Hook Leak (clipboard_44)

This PR addresses the memory leak identified in leak-report/guaranteed/clipboard_44.md.

Description

The useCopyToClipboard hook in webview-ui/src/utils/clipboard.ts uses a setTimeout to manage feedback visibility. This timeout is not cleared when the component unmounts, leading to potential React state update warnings on unmounted components.

This patch implements the suggested fix from the leak report, using useRef to store the timeout ID and useEffect to ensure the timeout is cleared on component unmount or when feedbackDuration changes.

Related Bug Report

#4227

Changes

  • Modified webview-ui/src/utils/clipboard.ts to correctly manage the setTimeout lifecycle.
    • Added useEffect and useRef.
    • Ensured clearTimeout is called on unmount and before setting a new timeout.
  • Add/update unit tests for useCopyToClipboard.

How to Test

  1. Integrate the useCopyToClipboard hook into a test component.
  2. Call copyWithFeedback.
  3. Unmount the test component before feedbackDuration (e.g., 2 seconds) expires.
  4. Verify that no React warnings about state updates on unmounted components appear in the console.

Important

Fixes memory leak in useCopyToClipboard by managing setTimeout lifecycle with useRef and useEffect.

  • Behavior:
    • Fixes memory leak in useCopyToClipboard in clipboard.ts by managing setTimeout lifecycle.
    • Uses useRef to store timeout ID and useEffect to clear timeout on unmount or feedbackDuration change.
  • Functions:
    • Modifies copyWithFeedback to clear existing timeout before setting a new one.
    • Adds cleanup logic in useEffect to clear timeout on component unmount.
  • Testing:
    • No unit tests added or updated for useCopyToClipboard.

This description was created by Ellipsis for a9b66bb. You can customize this summary. It will automatically update as commits are pushed.

@kiwina kiwina requested review from cte and mrubens as code owners June 2, 2025 04:35
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jun 2, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 2, 2025
@daniel-lxs
Copy link
Member

LGTM!

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jun 2, 2025
@daniel-lxs daniel-lxs changed the title fix: auto patch for clipboard_44 fix(clipboard): Clear setTimeout in useCopyToClipboard to resolve memory leak Jun 3, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 4, 2025
@mrubens mrubens merged commit 15b3713 into RooCodeInc:main Jun 4, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants